# -*- coding:utf-8
from functools import cmp_to_key
# .sorted(key=cmp_to_key(比较函数))
from typing import  List
class Solution:
    def __init__(self):
        self._data = []
    def rankTeams(self, votes: List[str]) -> str:
        n = votes.__len__()
        self._data = [[ 0 for j in range(26)] for i in range(26)]

        for voter in votes:
            for idx,c in enumerate(voter):
                self._data[ord(c)-ord("A")][idx] += 1



        def cmppMe(M,N):
            idxx = 0
            print(M,N)
            while (self._data[ord(M)- ord("A")][idxx] == self._data[ord(N) - ord("A")][idxx]):
                # idxx += 1
                if idxx< votes[0].__len__()-1:
                    idxx+=1
                elif idxx== votes[0].__len__()-1:
                    # print("M<N? ",M," ",N,M<N)
                    if M<N:
                        return -1
                    else:
                        return 1

            if self._data[ord(M)- ord("A")][idxx]> self._data[ord(N) - ord("A")][idxx]:
                return -1
            elif self._data[ord(M)- ord("A")][idxx]< self._data[ord(N) - ord("A")][idxx]:
                return 1

            if M < N:
                return -1
            else:
                return 1

        res = votes[0]
        print(res)
        resss = sorted(res,key=cmp_to_key(cmppMe))
        print(resss)
        return "".join(resss)

res = Solution().rankTeams(["BCA","CAB","CBA","ABC","ACB","BAC"])
print(res)


# def cmp(a,b):
#     if a%3 == 0:
#         return -1
#     return 1
# lis1= [1,2,3,4,5,1,6,2,3,6]
# # lis2 = [2,3,5]
# ll = sorted(lis1,key=cmp_to_key(cmp))
#
# print(ll)
# print("A">"B")
# print("C">"B")